package com.wd.mqtt;


import net.dreamlu.iot.mqtt.core.client.IMqttClientConnectListener;
import net.dreamlu.iot.mqtt.core.client.MqttClient;
import net.dreamlu.iot.mqtt.core.client.MqttClientCreator;
import org.smartboot.mqtt.client.MqttClientConfigure;
import org.tio.core.ChannelContext;

public class MicamqttImpl implements MqttClientApi {
    private String address;

    private MqttClient mqttClient;

    public MicamqttImpl(String address) {
        this.address = address;
    }

    @Override
    public void conect(String clientId) {

        String[] strs =  address.split(":");
        mqttClient =   MqttClient.create()
                .ip(strs[1].substring(2))
                .port(Integer.parseInt(strs[2]))
                .readBufferSize(1024)
                .maxBytesInMessage(1024)
                 .clientId(clientId)
                .keepAliveSecs(2)

                .connectListener(new IMqttClientConnectListener() {
                    @Override
                    public void onConnected(ChannelContext context, boolean isReconnect) {
                        System.out.println("连接成功");
                    }

                    @Override
                    public void onDisconnect(ChannelContext context, Throwable throwable, String remark, boolean isRemove) {
                        System.out.println("连接断开");

                    }
                })
                .connectSync();



    }

    @Override
    public void push() {

    }
}
